package com.rec.smile.rpc.registry.direct;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

import com.rec.smile.rpc.registry.RootRegistryApi;

public class SimpleDiscovery extends RootRegistryApi {

	private List<String> serverAddresses = new ArrayList<String>();
	
	public SimpleDiscovery(String serverAddresses) {
		this.serverAddresses.addAll(Arrays.asList(serverAddresses.split(",")));
	}

	@Override
	public String discover() {
		if(serverAddresses.isEmpty()){
			return null;
		}
		return serverAddresses.get(ThreadLocalRandom.current().nextInt(serverAddresses.size()));
	}

	

}
